def f(n):
    for i in range(2, n):
        if n % i == 0:   return False
    return True
cif = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
left=[]
right=[]
s = input()
a = s.split()
b = ''
for x in a:
    b += str(cif.index(x))
b=int(b)
for c in range(1, b):
    if f(c):
        left.append(c)
print(left)
for c in range(b, 1500):
    if f(c):
        right.append(c)
print(right)
con1 = b - left[-1]
con2 = right[0] - b
if con1 < con2:
    print(left[-1])
else:
    print(right[0])